<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta content="B2B电商平台" name="description" />
<meta content="B2B电商平台" name="keyword" />

<title>B2B电商平台.平台活动参与商品</title>
<link rel="icon" href="include/images/icss.ico" type="image/x-icon" />
<link rel="shortcut icon" href="include/images/icss.ico"
	type="image/x-icon" />
<link rel="stylesheet" type="text/css"
	href="<%=path%>/include/css/global.css" />
<link rel="stylesheet" type="text/css"
	href="<%=path%>/include/css/style.css" />
<link rel="stylesheet" type="text/css"
	href="<%=path%>/include/css/pro.css" />
<link rel="stylesheet" type="text/css"
	href="<%=path%>/include/css/proManage.css" />
<link rel="stylesheet"
	href="<%=path%>/include/JQuery ui/css/smoothness/jquery-ui-1.7.3.custom.css"
	type="text/css"></link>
<link rel="stylesheet" type="text/css"
	href="<%=path%>/include/pagination/page.css" media="all">
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/mmt_trading.css" />
<script type="text/javascript"
	src="<%=path%>/include/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="<%=path%>/include/js/cookies.js"></script>
<script type="text/javascript" src="<%=path%>/include/js/icss.busin.js"></script>
<script type="text/javascript"
	src="<%=path%>/include/JQuery ui/js/jquery-ui-1.7.3.custom.min.js"></script>
<script type="text/javascript" src="<%=path%>/include/js/icss.common.js"></script>
<script type="text/javascript"
	src="<%=path%>/include/pagination/jquery.pagination.js"></script>
<script type="text/javascript"
	src="<%=path%>/include/pagination/init.js"></script>
<script type="text/javascript" src="<%=path%>/include/js/doT.min.js"></script>
<script src="<%=path%>/include/DatePicker/WdatePicker.js"
	charset="UTF-8" type="text/javascript"></script>
<style type="text/css">
.table tr td {
	border-left: 1px solid #ddd;
	border-bottom: 1px solid #ddd;
	height: 33px;
}

.table tr th {
	border-left: 1px solid #ddd;
	font-weight: bold;
}

em.create {
	background-position: -50px -44px;
	line-height: 28px;
	display: inline-block;
	font-style: normal;
	background-repeat: no-repeat;
	text-indent: 15px;
	float: right;
	cursor: pointer;
}

.create {
	background: url("<%=path%>/images/coupons/sort_zss.png");
}

#queryId button {
	background-image: url("<%=path%>/include/css/img/xs_bgx.png");
	background-color: transparent;
}

.cxx_btn {
	width: 44px;
	height: 24px;
	background-position: 0px -203px;
	line-height: 24px;
	margin: 0px 0px 0px 5px;
}

a {
	color: #039;
}
</style>
<script type="text/javascript">
	$(function(){
		_search();
	});

	var pagination;
	function _search() {
		var url = "<%=path%>/activityList/product_getProductList.do";
		var data = {
			productName :$("#productName").val(),
			activityUuid : $("#activityUuid").val(),
			minPriceStr : $("#minPriceStr").val(),
			maxPriceStr : $("#maxPriceStr").val()
		};
		pagination = _initPagination({
			'pageId' : 'pagination',
			'url' : url,
			'data' : data,
			'rows' : 5,
			'callback' : _initDataList
		});
	}

	function _initDataList(data) {
		var tpl = $('#dataTpl').html();
		$('#tbody').html(doT.template(tpl)(data.rows));
	}
	
	//处理查询条件的默认值
    //参数：id;ovalue原值;nvalue 新值; type：事件类型（1表示获取焦点 2表示失去焦点）
    function clearDefaultVal(id,type,ovalue,nvalue){
        if(type==1){//判断事件类型(获取焦点,情况现有默认值)
            jQuery("#"+id).val("");
        }else{
            //失去焦点，值为空，赋默认值
            if(nvalue==""){
                jQuery("#"+id).val(ovalue);
            }
        }
    }
    
    function selectAlledTop(){
    	if($("#topCheckAll").attr("checked")=="checked"){
		    $("input[name='activityProUuid']").each(function(index,item){
		    		$(this).attr("checked",true);
		    })
		    $("#checkAll").attr("checked",true);
    	}else{
		    $("input[name='activityProUuid']").each(function(index,item){
		    		$(this).attr("checked",false);
		    })
		    $("#checkAll").attr("checked",false);
    	}
    }
    
    //去添加商品页面
    function addProduct(){
    	var activityUuid=$("#activityUuid").val();
    	window.location.href="<%=path%>/activityList/product_toAddProductPage.do?activityUuid="+activityUuid;
    }
    
    //删除
    function _delete(productId){
    	var activityUuid=$("#activityUuid").val();
    	parent.swal({
                        title: "删除商品",
                        text: "确认从活动中删除该商品吗？",
                        type: "info",
                        showConfirmButton:true,  
                        showCancelButton: true,
                        closeOnConfirm: true,
                        cancelButtonText: "取消",
						confirmButtonText: "确认",
						confirmButtonColor: "#ec6c62",
                        animation: "slide-from-top",
                    }, function(inputValue) {
                    	if(inputValue){
                    			$.ajax({
                        			url:"<%=path%>/activityList/product_deleteProduct.do",
                        			type:"post",
                        			data:{"productId":productId,"activityUuid":activityUuid},
                        			success:function(result){
                        				if (result.success == undefined) {
											result = eval('(' + result + ')');
										}
                        				if(result.success){
                        				 	parent.swal("成功删除该商品!");
                        				}
                        				window.location.reload();
                        			}	
                        
                        		});
                    	}
                    });
    }
    
    //批量删除商品
    function deleteProducts(){
    	var activityUuid=$("#activityUuid").val();
		var activityProUuids ="";
    	$("input[name='activityProUuid']").each(function(index,item){
    		 if($(this).attr("checked")=="checked"){
    			 activityProUuids +=","+ $(this).val();
        	 }
	    });
	    activityProUuids=activityProUuids.substring(1);
	    if(activityProUuids==""){
		    parent.swal("请至少选择一条记录!");
		    return;
		}else{
			parent.swal({
                        title: "删除商品",
                        text: "确认从活动中删除该商品吗？",
                        type: "info",
                        showConfirmButton:true,  
                        showCancelButton: true,
                        cancelButtonText: "取消",
                        closeOnConfirm: true,
                        animation: "slide-from-top",
                    }, function(inputValue) {
                    	if(inputValue){
                    			$.ajax({
									type:"post",
									url: "<%=path %>/activityList/product_deleteProducts.do",
									data:{"activityProUuids":activityProUuids,"activityUuid":activityUuid},
									dataType:"json",
									success:function(result){
										if (result.success == undefined) {
											result = eval('(' + result + ')');
										}
                    					if(result.success){
                        					parent.swal("删除成功!");
                   	 					}
                    					window.location.reload();
									}
								});
                    	}
                    });
			
			
		}
    }
	
</script>
</head>

<body style="font-family: '微软雅黑';">
	<div id="contentDiv">
  
    <div class="colnums-2-ab-b">
    	<div class="toptil">
    		<a style="color: black;" href="<%=path %>/activityList/activity_toActivityPage.do">平台活动</a>→参与商品
			
    	</div>	
    		<input type="hidden" id="activityUuid" name="activityUuid" value="${activityUuid }"/>
		<div class="search_lis" style="border: 1px solid #e0e0e0;background: #f5f5f5;padding-left:10px;margin-bottom:10px;"><!--search_lis S-->
        <div class="search_lis_se"><!--search_lis_se S-->
           	<span>商品名称:</span><input name="productName" id="productName" type="text" class="in_bit" maxlength="40"   onblur="clearDefaultVal('productName',2,'',this.value)" onfocus="clearDefaultVal('productName',1,'','')">
            
             
            <span>价格:</span>

            <input name="minPriceStr" id="minPriceStr" type="text" class="in_price"  maxlength="10" style="color:#999"  onblur="clearDefaultVal('minPriceStr',2,'',this.value)" onfocus="clearDefaultVal('minPriceStr',1,'','')">
            <i>-</i>
            <input name="maxPriceStr" id="maxPriceStr" type="text" class="in_price"  maxlength="10" style="color:#999"  onblur="clearDefaultVal('maxPriceStr',2,'',this.value)" onfocus="clearDefaultVal('maxPriceStr',1,'','')">
            
            &nbsp;&nbsp;
            <button type="button" class="cxx_btn" onclick="_search()" >查询</button>
            <button type="button" class="cxx_btn" onclick="addProduct()" >添加</button>
            <div class="clear"></div>
            <div id="nomore" style="display: none;">&nbsp;
           </div>
           
        </div>
        <div class="wantBuy" id="caigouInfo">
        </div>
    	</div>
    	
    
		<div class="listed_tb_k">
        <div class="list_table_bot">
            <div  style="margin-bottom: 7px;">
                <label><input id="topCheckAll" name="topCheckAll" type="checkbox" onclick="selectAlledTop()" class="chk">全选</label>
                <button class="gray_btn" type="button" onclick="javascript:deleteProducts()">删除</button>
            </div>
        </div>
        <table cellspacing="0" cellpadding="0">
            <thead>
            <tr>
                <th class="t1" style="text-align:center;vertical-align: middle" >选项</th>
                <th class="t2" style="text-align:center;vertical-align: middle" >图片</th>
                <th class="t3" style="text-align:center;vertical-align: middle" >商品名称</th>
                <th class="t3" style="text-align:center;vertical-align: middle" >参与活动</th>
                <th class="t4" style="text-align:center;vertical-align: middle" >价格</th>
                <th class="t5" style="text-align:center;vertical-align: middle;text-align: center" >下架日期</th>
                <th class="t6" style="text-align:center;vertical-align: middle" >操作</th>
            </tr>
            </thead>
            <tbody id="tbody">
			</tbody>
	        </table>
	    </div>

</div>
</div>
</body>
<script type="text/javascript">
	$(document).ready(function() {
		_reHeight("rightFrame", "contentDiv");
	});
</script>
<script id="dataTpl" type="text/template">
		{{ for (var i = 0; i < it.length; i ++) { }}  
		{{     var row = it[i]; }}
			<tr style='line-height: 20px;white-space: nowrap;'>
				<td style='text-align:center;vertical-align: middle;width:6%;'>
					<input type='checkbox' name='activityProUuid' value='{{=row.activityProUuid}}' star='3' mainpro=''>
				</td>
				<td style='text-align:center;vertical-align: middle;'>
					<img src='{{=row.productPic}}' width='50' height='50' alt='' resizeimg='true' onmousedown='' onerror='javascript:this.src="<%=path%>/download/error/nopicture.jpg"' style='width: 50px; height: 43.5px;'>
				</td>
				<td style='text-align:left;vertical-align: middle;'>&nbsp;{{=row.productName}}</td>
				<td style='text-align:center;vertical-align: middle;'>&nbsp;{{=row.activityName}}</td>
				<td style='text-align:right;vertical-align: middle;'>{{=row.productPrice}}&nbsp;</td>
				<td style='text-align:center;vertical-align: middle;'>{{=row.downTime}}</td>
				<td style='text-align:center;vertical-align: middle;'>
					<a href="javascript:_delete('{{=row.productId}}')">删除</a>
				</td>
		     </tr>
		{{ } }}
	</script>
</html>
